gdk: Add gdk_content_formats_new_for_gtype()
authorBenjamin Otte <otte@redhat.com>
Tue, 28 Nov 2017 01:02:06 +0000 (02:02 +0100)
committerBenjamin Otte <otte@redhat.com>
Sun, 3 Dec 2017 04:46:48 +0000 (05:46 +0100)
Many places create formats for a single tpye, so make it easy for them
to get this without having to create a builder first.

docs/reference/gdk/gdk4-sections.txt
gdk/gdkcontentformats.c
gdk/gdkcontentformats.h
gdk/gdkcontentproviderimpl.c

index 8deed84aac2e9921ed2f39feb248480b8fa8f0f3..ec1159476ab2a9fc69e55ac03990bfed56a6a08d 100644 (file)
@@ -372,6 +372,7 @@ gdk_intern_mime_type
 <SUBSECTION>
 GdkContentFormats
 gdk_content_formats_new
+gdk_content_formats_new_for_gtype
 gdk_content_formats_ref
 gdk_content_formats_unref
 gdk_content_formats_print
index 8369cdd6ee760be45199ed7567cdee6d61b995cf..5e7d5ea2f5183825fd046ddaec70077b95e26ed0 100644 (file)
@@ -137,9 +137,9 @@ gdk_content_formats_new_take (GType *      gtypes,
  * 
  * Creates a new #GdkContentFormats from an array of mime types.
  *
- * The mime types must be different or the behavior of the return value
- * is undefined. If you cannot guarantee this, use #GdkContentFormatsBuilder
- * instead.
+ * The mime types must be valid and different from each other or the
+ * behavior of the return value is undefined. If you cannot guarantee
+ * this, use #GdkContentFormatsBuilder instead.
  * 
  * Returns: (transfer full): the new #GdkContentFormats.
  **/
@@ -161,6 +161,28 @@ gdk_content_formats_new (const char **mime_types,
   return gdk_content_formats_new_take (NULL, 0, (const char **) g_ptr_array_free (array, FALSE), n_mime_types);
 }
 
+/**
+ * gdk_content_formats_new_for_gtype:
+ * @type: a $GType
+ *
+ * Creates a new #GdkContentFormats for a given #GType.
+ *
+ * Returns: a new #GdkContentFormats
+ **/
+GdkContentFormats *
+gdk_content_formats_new_for_gtype (GType type)
+{
+  GType *data;
+
+  g_return_val_if_fail (type != G_TYPE_INVALID, NULL);
+
+  data = g_new (GType, 2);
+  data[0] = type;
+  data[1] = G_TYPE_INVALID;
+
+  return gdk_content_formats_new_take (data, 1, NULL, 0);
+}
+
 /**
  * gdk_content_formats_ref:
  * @formats:  a #GdkContentFormats
index e265b6ab8863e4f1acc505ebeeeefd01ef2bd477..1e5f7147bba305dcd2250b0a9a4e072e3c4989e5 100644 (file)
@@ -39,6 +39,8 @@ GDK_AVAILABLE_IN_3_94
 GdkContentFormats *     gdk_content_formats_new                 (const char                    **mime_types,
                                                                  guint                           n_mime_types);
 GDK_AVAILABLE_IN_3_94
+GdkContentFormats *     gdk_content_formats_new_for_gtype       (GType                           type);
+GDK_AVAILABLE_IN_3_94
 GdkContentFormats *     gdk_content_formats_ref                 (GdkContentFormats              *formats);
 GDK_AVAILABLE_IN_3_94
 void                    gdk_content_formats_unref               (GdkContentFormats              *formats);
index 77e4d8d3e019a8286b3b2e8ce29fdf041b89adb5..adb3cc4d89f16cd4c7770af947f22afc3f435f2c 100644 (file)
@@ -64,11 +64,8 @@ static GdkContentFormats *
 gdk_content_provider_value_ref_formats (GdkContentProvider *provider)
 {
   GdkContentProviderValue *content = GDK_CONTENT_PROVIDER_VALUE (provider);
-  GdkContentFormatsBuilder *builder;
 
-  builder = gdk_content_formats_builder_new ();
-  gdk_content_formats_builder_add_gtype (builder, G_VALUE_TYPE (&content->value));
-  return gdk_content_formats_builder_free (builder);
+  return gdk_content_formats_new_for_gtype (G_VALUE_TYPE (&content->value));
 }
 
 static gboolean